﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace project
{
    public partial class SupplierUpdate : Form
    {
        private SupplierManage supplierManage;
        public SupplierUpdate(string id,SupplierManage supplierManage)
        {
            this.supplierManage = supplierManage;
            InitializeComponent();
            InitDta(id);
        }

        private void SupplierUpdate_Load(object sender, EventArgs e)
        {
           
        }
        public void InitDta(string id)
        {
            string sql = "select * from Supplier where Id="+id;
            DataTable dt= DBHelper.GetTable(sql);
            this.textBoxId.Text= dt.Rows[0]["Id"].ToString();
            this.textBoxName.Text = dt.Rows[0]["SupplierName"].ToString();
            this.textBoxPhone.Text = dt.Rows[0]["Phone"].ToString();
            this.textBoxEmail.Text = dt.Rows[0]["Email"].ToString();
            this.textBoxBankId.Text = dt.Rows[0]["BankId"].ToString();
            this.textBoxContact.Text = dt.Rows[0]["Contact"].ToString();
            this.textBoxAddress.Text= dt.Rows[0]["Address"].ToString();

        }

        private void buttonSave_Click(object sender, EventArgs e)
        {
            string address = this.textBoxAddress.Text, name = this.textBoxName.Text, phone = this.textBoxPhone.Text, bankId = this.textBoxBankId.Text, email = this.textBoxEmail.Text, contact = this.textBoxContact.Text, id = this.textBoxId.Text;
            string sql = "UPDATE [dbo].[Supplier]SET [SupplierName] = '{0}',[Phone] = '{1}',[Email] = '{2}',[Contact] = '{3}',[BankId] = '{4}',[Address] = '{5}'WHERE Id={6}";
            sql = string.Format(sql,name,phone,email,contact,bankId,address,id);
            int re= DBHelper.ExecuteNonQuery(sql);
            if (re>0)
            {
                MessageBox.Show("修改成功");
                this.supplierManage.InitData();
                this.Close();

            }
        }
    }
}
